<?php
namespace app\app\model;

use think\Model;
use think\exception\DbException;
class Main extends Model
{
	public function register_ouser(array $ouser_info)
	{
		$result = [
				'err' => '1',
				'content' => '注册失败！'
		];
		$exists_ouser = db('ouser')->field(['id'])->where('user_name',$ouser_info['user_name'])->select();
		if ($exists_ouser != false || !empty($exists_ouser)){
			$result['content'] = '该用户名已存在于用户表！';
			return $result;
		}
		
		
		$exists_ousertmp = db('ousertmp')->field(['id'])->where(['user_name'=>$ouser_info['user_name'],'if_agree'=>'0'])->select();
		if ($exists_ousertmp != false || !empty($exists_ousertmp)){
			$result['content'] = '该用户已经注册！';
			return $result;
		}
		try {
			$ouser_info['created'] = time();
			$ouser_info['password'] = md5($ouser_info['password']);
			$ouser_tmp_id = db('ousertmp')->failException()->insert($ouser_info);	
		}catch (DbException $e){
			$result['content'] =$e->getMessage();
			return $result;
		}
// 		$ouser_tmp_id = db('ousertmp')->insert($ouser_info);
		$result['err'] = '0';
		$result['content'] = $ouser_tmp_id;
		
		return $result;
	}
}